//Tue 22 Dec 2009 01:14:05 AM CST 
//Mon 08 Feb 2010 11:22:09 PM CST 
//Simple simulation;
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class InstantRunoffVoting
{
public:
	int winner(vector <string> voters)
	{
		int N = voters.size();
		int M = voters[0].size();
		int cnt = M;
		vector<bool>  visit(voters[0].size(), true);
		while(true)
		{
			vector<int> v(M, 0);
			for(int i=0; i<N; i++)
			{
				for(int j=0; j<M; j++)
				{
					int idx = voters[i][j] - '0';
					if(visit[idx])
					{
						v[idx] ++;
						break;
					}
				}
			}
			int mmin = 1<<20;
			for(int i=0; i<M; i++)
			{
				if(visit[i])
				{
					if(2*v[i] > N) return i;
					else mmin = min(mmin, v[i]);
				}
			}
			for(int i=0; i<M; i++)
			{
				if(visit[i])
				{
					if(v[i] == mmin)
					{
						cnt--;
						visit[i] = false;
					}
				}
			}
			if(cnt == 0) return -1;
		}
	}
};
